﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace Sonce.Controls //.Primitives
{
    public partial class MenuItemHeader : Button
    {
        #region Members
        private bool isMainMenuItem = false;
        #endregion

        #region Constructor
        public MenuItemHeader()
            : base()
        {
            this.DefaultStyleKey = typeof(MenuItemHeader);
        }
        #endregion

        #region Properties
        public bool IsMainMenuItem
        {
            get
            {
                return this.isMainMenuItem;
            }
            set
            {
                this.isMainMenuItem = value;
                if (this.ArrowColumn != null)
                {
                    this.ArrowColumn.Width = (value ? new GridLength(0) : new GridLength(12));
                }
                if (this.Arrow != null && value)
                {
                    //Only if is main menu item
                    this.ArrowVisibility = Visibility.Collapsed;
                    this.Arrow.Visibility = this.ArrowVisibility;
                }
            }
        }

        public Visibility ArrowVisibility
        {
            get
            {
                return (Visibility)GetValue(ArrowVisibilityProperty);
            }
            set
            {
                SetValue(ArrowVisibilityProperty, value);
            }
        }

        public double ArrowContainerWidth
        {
            get
            {
                return (double)GetValue(ArrowContainerWidthProperty);
            }
            set
            {
                SetValue(ArrowContainerWidthProperty, value);
            }
        }

        public Thickness ContentPadding
        {
            get
            {
                return (Thickness)GetValue(ContentPaddingProperty);
            }
            set
            {
                SetValue(ContentPaddingProperty, value);

            }
        }
        #endregion

        #region Template
        protected FrameworkElement RootElement;
        protected ColumnDefinition ArrowColumn;
        protected TextBlock Content;
        protected Path Arrow;

        public override void OnApplyTemplate()
        {
            RootElement = (FrameworkElement)GetTemplateChild("RootElement");
            ArrowColumn = (ColumnDefinition)GetTemplateChild("ArrowColumn");
            Content = (TextBlock)GetTemplateChild("Content");
            Arrow = (Path)GetTemplateChild("Arrow");
            this.IsMainMenuItem = this.isMainMenuItem;
        }
        #endregion

        #region Dependency
        public static readonly DependencyProperty ArrowVisibilityProperty = DependencyProperty.Register("ArrowVisibility", typeof(Visibility), typeof(MenuItemHeader), new PropertyMetadata(null));
        public static readonly DependencyProperty ArrowContainerWidthProperty = DependencyProperty.Register("ArrowContainerWidth", typeof(double), typeof(MenuItemHeader), new PropertyMetadata(null));
        public static readonly DependencyProperty ContentPaddingProperty = DependencyProperty.Register("ContentPadding", typeof(Thickness), typeof(MenuItemHeader), new PropertyMetadata(null));
        #endregion
    }
}
